package com.apache.springboot.service.impl;

import com.apache.springboot.bean.Customer;
import com.apache.springboot.mapper.CustomerMapper;
import com.apache.springboot.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service  //标志为业务层组件 (Spring) -> Spring 会自动创建该类的对象(单例)，并管理到Spring容器中
//默认的名字就是类名首字母小写形式 -> customerServiceImpl
//@Service(value = "csi") -> 自己指定的名字，不是默认的名字了
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    CustomerMapper customerMapper;

    public String doLogin(String username, String password) {

        System.out.println("CustomerService : 复杂的业务处理");
        //非空格式校验

        //数据格式的校验

        //.......

        //调用数据层，对比数据库是否一致
        Customer customer = customerMapper.searchByUsernameAndPassword(username, password);
        if (customer != null) {
            return "成功!";
        } else {
            return "有毛病!";
        }

        //return "ok"; //error
    }
}
